unit UfrmClientSelect;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DBGridEhGrouping, RzPanel, GridsEh, DBGridEh, ExtCtrls, DB,
  DBClient, StdCtrls, Mask, RzEdit, RzButton,RLLibrary_Intf;

type
  TfrmClientSelect = class(TForm)
    RzPanel1: TRzPanel;
    DBGridEhClient: TDBGridEh;
    RzStatusBar1: TRzStatusBar;
    dsClient: TDataSource;
    cdsClient: TClientDataSet;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    edtClientName: TRzEdit;
    edtSpell: TRzEdit;
    edtPhone: TRzEdit;
    btnSearcher: TRzBitBtn;
    btnselect: TRzBitBtn;
    RzBitBtn3: TRzBitBtn;
    cdsClientclientid: TIntegerField;
    cdsClientclientnumber: TStringField;
    cdsClientclientname: TStringField;
    cdsClienttelephone: TStringField;
    cdsClientmobilephone: TStringField;
    cdsClientaddress: TStringField;
    cdsClientspell: TStringField;
    cdsClientremainsum: TFloatField;
    cdsClientclientlinker: TStringField;
    cdsClientlinker: TStringField;
    procedure FormCreate(Sender: TObject);
    procedure btnSearcherClick(Sender: TObject);
    procedure RzBitBtn3Click(Sender: TObject);
    procedure btnselectClick(Sender: TObject);
    procedure DBGridEhClientDblClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure edtSpellKeyPress(Sender: TObject; var Key: Char);
    procedure edtClientNameKeyPress(Sender: TObject; var Key: Char);
    procedure edtPhoneKeyPress(Sender: TObject; var Key: Char);
    procedure btnSearcherKeyPress(Sender: TObject; var Key: Char);
  private
     iorder:IOrderService;
     FSelectResult:Variant;
     procedure GetClientByParam;
     function GetSelectData: Variant;
  protected
     procedure SetSelectResult(v:Variant);
  public
      function GetSelectResult:Variant;
  end;

var
  frmClientSelect: TfrmClientSelect;

implementation

uses Udatamodule,uROBinaryHelpers;

{$R *.dfm}

procedure TfrmClientSelect.FormCreate(Sender: TObject);
begin

   iorder:=dm.GetIOrder;
end;

procedure TfrmClientSelect.GetClientByParam;
begin
  cdsClient.Data:= VariantFromBinary(  iorder.GetClient(edtClientName.Text,UpperCase( edtSpell.Text),edtPhone.Text) );
end;

function TfrmClientSelect.GetSelectData: Variant;

begin
  Result:= VarArrayOf( [cdsClient.FieldByName('clientid').Value,
                        cdsClient.FieldByName('clientname').Value,
                        cdsClient.FieldByName('remainsum').Value]);
end;

procedure TfrmClientSelect.btnSearcherClick(Sender: TObject);
begin
   GetClientByParam;
end;

procedure TfrmClientSelect.RzBitBtn3Click(Sender: TObject);
begin
   edtClientName.Text:='';
   edtSpell.Text:='';
   edtPhone.Text:='';
   GetClientByParam;
end;

procedure TfrmClientSelect.btnselectClick(Sender: TObject);
begin
   SetSelectResult(GetSelectData);
   Close;
end;

procedure TfrmClientSelect.DBGridEhClientDblClick(Sender: TObject);
begin
     btnselect.Click;
end;

procedure TfrmClientSelect.FormShow(Sender: TObject);
begin
  GetClientByParam;
end;

procedure TfrmClientSelect.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#27 then close;
end;

function TfrmClientSelect.GetSelectResult: Variant;
begin
    Result:=FSelectResult;
end;

procedure TfrmClientSelect.SetSelectResult(v: Variant);
begin
     FSelectResult:=v;
end;

procedure TfrmClientSelect.edtSpellKeyPress(Sender: TObject;
  var Key: Char);
begin
  if key=#13 then  GetClientByParam;
end;

procedure TfrmClientSelect.edtClientNameKeyPress(Sender: TObject;
  var Key: Char);
begin
  if key=#13 then  GetClientByParam;
end;

procedure TfrmClientSelect.edtPhoneKeyPress(Sender: TObject;
  var Key: Char);
begin
  if key=#13 then   GetClientByParam;
end;

procedure TfrmClientSelect.btnSearcherKeyPress(Sender: TObject;
  var Key: Char);
begin
   if key=#13 then  GetClientByParam;
end;

end.
